﻿using Sirenix.OdinInspector;
using UnityEngine;

namespace HotPlayer.Physic2D
{
    public class TestGJK : MonoBehaviour
    {
        public HotPolygonCollider2D collider1;
        
        public HotPolygonCollider2D collider2;

        [Button]
        public void TestCollide()
        {
            collider1.RefreshShape();
            collider2.RefreshShape();
            
            var isCollide = HotPhysic2DEngine.TestCollideGJK(collider1.shape, collider2.shape, out var direction, out var point);
            Debug.Log($"{isCollide}, {direction}, {point}");
            if (isCollide)
            {
                var endPoint = point + direction;
                var startPoint = new Vector3(point.x, 0, point.y);
                Debug.DrawLine(startPoint, startPoint + new Vector3(0,10,0), Color.yellow, 10, false);
                Debug.DrawLine(startPoint, new Vector3(endPoint.x, 0, endPoint.y), Color.red, 10, false);
            }
        }
    }
}